<?php
/*
 * estudo de padrões de projetos com php
 * author: fabricio s costa
 * version: 1.0
 * site: http://fabriciojf.com
 */
//segurança
require_once('com/fabriciojf/security/Permission.class.php');
require_once('smarty/SmartyInclude.php');
require_once('com/fabriciojf/include/Menu.class.php');

Permission::requireInRole(array('admin','usuario'));

$smarty = SmartyInclude::getSmarty();

$pagina = $_REQUEST["pagina"];
$posts = $pagina->getObjeto();

// carrega os valores dos objetos nos vetores
foreach ($posts as $row){
    $idPost[] = $row->getId();
    $titulo[] = $row->getTitulo();    
    $dataCriacao[] = Data::formatarDataExtenso($row->getDataCriacao());
    $author[] = 'Fabriciojf';
}

$menusuperior =
'<div class="menusuperior">' .    
'    <a href="do.php?action=Home" class="menuesquerdo">Home</a>&nbsp;>&nbsp;Painel de Controle' .
'    <a href="do.php?action=Logout" class="menudireito">Logout</a>' .
'    <div class="clear"></div> ' .
'</div>';

$menuprincipal =
'<table style="width:350px;margin: 40px auto;"> ';

if (Permission::isInRole(array('admin'))) {
$menuprincipal .=
'    <tr> ' .
'       <td><a href="do.php?action=CadastroPost" style="font-size:17px;">Criar Nova Postagem ou P&aacute;gina</a></td> ' .
'    </tr> ';

} else if (Permission::isInRole(array('usuario'))) {
$menuprincipal .=
'    <tr> ' .
'       <td><a href="do.php?action=TicketCriar" style="font-size:17px;">Criar Novo Chamado de Suporte</a></td> ' .
'    </tr> ';
}

$menuprincipal .=
'    <tr> ' .
'       <td><a href="do.php?action=TicketListar" style="font-size:17px;">Listar Todos os Chamados de Suporte</a></td> ' .
'    </tr> '.
'</table>';

// carrega o template
/* menu */
$smarty->assign('menuon',  Menu::getMenuOn());
$smarty->assign('menupost', Menu::getMenuPost());
$smarty->assign('menupage', Menu::getMenuPages());
$smarty->assign('menuticket', Menu::getMenuTicket());
$smarty->assign('menupostinativos', Menu::getMenuPostInativos());
$smarty->assign('menusuperior', Menu::getMenuSuperior());
$smarty->assign('menuprincipal', $menuprincipal);

$smarty->assign('idPost', $idPost);
$smarty->assign('titulo', $titulo);
$smarty->assign('dataCriacao', $dataCriacao);
$smarty->assign('author', $author);

$smarty->display('PainelControle.tpl');

?>
